package controller.servletCadastro;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.classe.Noticia;
import model.classesDAO.NoticiaDAO;
import model.factory.Fabrica;


@WebServlet("/ServletCadastroNoticia")
public class ServletCadastroNoticia extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
    public ServletCadastroNoticia() {
        super();
        
    }
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		RequestDispatcher rd = null;
		String noticia = request.getParameter("noticia");
		String chamada = request.getParameter("chamada");
		String fonte = request.getParameter("fonte");
		String autor = request.getParameter("autor");
		
		Noticia not = new Noticia();
		not.setNoticia(noticia);
		not.setChamada(chamada);
		not.setFonte(fonte);
		not.setAutor(autor);
		
		NoticiaDAO notdao = Fabrica.getNoticiaDAO();
		notdao.cadastrar(not);
		
		rd = request.getRequestDispatcher("/index.jsp");
		rd.forward(request, response);
		
	}

}
